//
// Created by xili on 2024/9/15 20:22.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int numRescueBoats(vector<int> &people, int limit) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int l = people.size(), i = 0, j = l - 1;
        sort(people.begin(), people.end());
        for (; i < j; i += people[i] + people[j--] <= limit);
        return l - i;
    }
};